1 // Accepted, trying to make it run faster.
25 #define foreach(x, v) for (typeof (v).begin() x=(v).begin(); x !=(v).end(); ++x)
26 #define For(i, a, b) for (int i=(a); i<(b); ++i)
27 #define D(x) cout << #x " is " << x << endl
30 #define MAXBUFF (1<<20)
31 char buffer
[MAXBUFF
], *p
= buffer
+MAXBUFF
;
32 char buffer2
[MAXBUFF
], *p2
= buffer2
;
34 inline char read_char() {
35 if( p
== buffer
+MAXBUFF
) {
36 fread( buffer
, 1, MAXBUFF
, stdin
);
42 inline int read_int() {
44 while( !isdigit(c
) and c
!= '-' ) c
= read_char();
45 int sign
= c
== '-' ? -1 : +1;
46 if (c
== '-') c
= read_char();
48 while( isdigit(c
= read_char()) ) ret
= ret
* 10 + c
-'0';
53 fwrite( buffer2
, 1, p2
-buffer2
, stdout
);
57 inline void write( char c
) {
58 if( p2
== buffer2
+MAXBUFF
) {
59 fwrite( buffer2
, 1, MAXBUFF
, stdout
);
68 point(){} point(int x
, int y
) : x(x
), y(y
) {}
69 bool operator < (const point
&t
) const {
70 return x
* t
.y
- y
* t
.x
> 0;
72 bool operator == (const point
&t
) const {
73 return x
* t
.y
- y
* t
.x
== 0;
75 bool operator <= (const point
&t
) const {
76 return *this < t
or *this == t
;
78 bool operator != (const point
&t
) const {
83 typedef pair
< point
, point
> interval
;
85 // Returns true if interval 'a' is strictly included in interval 'b'
86 inline bool included(const interval
&a
, const interval
&b
) {
87 return b
.first
< a
.first
and a
.second
< b
.second
;
90 const int MAXN
= 1001;
92 interval intervals
[MAXN
];
95 inline void delete_redundant() {
97 for (int i
= 0; i
< B
; ++i
) {
98 for (int j
= 0; j
< B
; ++j
) {
99 // delete interval i if interval j is completely inside it
100 if (included(intervals
[j
], intervals
[i
])) {
107 for (int i
= 0; i
< B
; ++i
) {
109 intervals
[k
++] = intervals
[i
];
118 while (B
= IO::read_int()) {
119 for (int i
= 0; i
< B
; ++i
) {
121 intervals
[i
].first
.x
= IO::read_int();
122 intervals
[i
].first
.y
= IO::read_int();
123 intervals
[i
].second
.x
= IO::read_int();
124 intervals
[i
].second
.y
= IO::read_int();
125 if (intervals
[i
].second
< intervals
[i
].first
) swap(intervals
[i
].first
, intervals
[i
].second
);
127 //printf("Before removing redundant B is %d\n", B);
129 sort(intervals
, intervals
+ B
);
130 //printf("After removing redundant B is %d\n", B);
132 //printf("Before removing duplicates B is %d\n", B);
133 B
= unique(intervals
, intervals
+ B
) - intervals
;
134 //printf("After removing duplicates B is %d\n", B);
139 point pick
= intervals
[i
].second
;
140 while (i
< B
and intervals
[i
].first
<= pick
) i
++;
142 sprintf(buf
, "%d\n", ans
);
143 for (char * c
= buf
; *c
; ++c
) IO::write(*c
);